<?php

namespace app\student\controller;

use app\student\model\Thesis as ThesisModel;
use app\student\security\StuCheck as StuCheckLogic;
use app\student\security\Auth as AuthLogic;
use app\student\model\Select as SelectLogic;
use think\Controller;
use think\Session;

class ThesisList extends Controller
{
    /**
     * 登录界面显示，自动登录
     * @access public
     * @return mixed 返回登录视图
     */
    public function thesisList()
    {
        //检测学生登录情况
        $stuCheck = new StuCheckLogic();
        if ($stuCheck->check() == 1) {
            //检测是否有查看个人列表权限
            $auth = new AuthLogic();
            $username=Session::get('token')['stuUsername'];
            if ($auth->check('selectlist',$username )) {
                if(getSrvConfig()['srvStatus']==4) {
                    $thesis = new ThesisModel();
                    //定义需要查询的字段
                    $field = 'tisId,tisTitle,tisSourceName,tisTypeName,tisMain,tisAsk,tisCount';
                    //显示题目状态
                    $tisStatus = getSrvConfig()['srvStatus'];
                    $select=new SelectLogic();
                    //查找已经选择的课程
                    if($selected=$select::where('stuUsername',$username)->find()){
                        $this->assign('selected',$selected['tisId']);
                    }
                    $result = $thesis::where('')->field($field)->select();
                    if ($result !== false) {
                        $this->assign('tisStatus', $tisStatus);
                        $this->assign('thesisList', $result);
                    } else {
                        return "查询出错，请稍后再试";
                    }
                }else{
                    return "目前不是选题阶段";
                }
            } else {
                return "错误500：您没有添加题目的权限";
            }
        } else {
            return "错误600：您的登录信息出现问题，请重新登录"
            . "<br>" . "1.您的帐号在其他地方登录"
            . "<br>" . "2.您在线时间过长（5小时以上）"
            . "<br>" . "3.令牌验证错误";
        }

        return $this->fetch('thesisList/thesisList');
    }
}